<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>cancel_after (4 of 6 overloads)</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../boost_asio.html" title="Boost.Asio">
<link rel="up" href="../cancel_after.html" title="cancel_after">
<link rel="prev" href="overload3.html" title="cancel_after (3 of 6 overloads)">
<link rel="next" href="overload5.html" title="cancel_after (5 of 6 overloads)">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="overload3.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cancel_after.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload5.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_asio.reference.cancel_after.overload4"></a><a class="link" href="overload4.html" title="cancel_after (4 of 6 overloads)">cancel_after
        (4 of 6 overloads)</a>
</h4></div></div></div>
<p>
          Adapt a <a class="link" href="../../overview/model/completion_tokens.html" title="Completion Tokens">completion
          token</a> to cancel an operation if not complete before the specified
          relative timeout has elapsed.
        </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span>
    <span class="keyword">typename</span> <span class="identifier">Rep</span><span class="special">,</span>
    <span class="keyword">typename</span> <span class="identifier">Period</span><span class="special">,</span>
    <span class="keyword">typename</span> <span class="identifier">CompletionToken</span><span class="special">&gt;</span>
<span class="identifier">cancel_after_t</span><span class="special">&lt;</span> <span class="identifier">decay_t</span><span class="special">&lt;</span> <span class="identifier">CompletionToken</span> <span class="special">&gt;,</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">steady_clock</span> <span class="special">&gt;</span> <span class="identifier">cancel_after</span><span class="special">(</span>
    <span class="keyword">const</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special">&lt;</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span> <span class="special">&gt;</span> <span class="special">&amp;</span> <span class="identifier">timeout</span><span class="special">,</span>
    <span class="identifier">cancellation_type_t</span> <span class="identifier">cancel_type</span><span class="special">,</span>
    <span class="identifier">CompletionToken</span> <span class="special">&amp;&amp;</span> <span class="identifier">completion_token</span><span class="special">);</span>
</pre>
<h6>
<a name="boost_asio.reference.cancel_after.overload4.h0"></a>
          <span class="phrase"><a name="boost_asio.reference.cancel_after.overload4.thread_safety"></a></span><a class="link" href="overload4.html#boost_asio.reference.cancel_after.overload4.thread_safety">Thread
          Safety</a>
        </h6>
<p>
          When an asynchronous operation is used with cancel_after, a timer async_wait
          operation is performed in parallel to the main operation. If this parallel
          async_wait completes first, a cancellation request is emitted to cancel
          the main operation. Consequently, the application must ensure that the
          asynchronous operation is performed within an implicit or explicit strand.
        </p>
</div>
<div class="copyright-footer">Copyright © 2003-2025 Christopher M.
      Kohlhoff<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="overload3.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cancel_after.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../boost_asio.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overload5.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
